const EventEmitter=require("events")

function Dog(name,energy){
    EventEmitter.call(this);//继承EventEmitter
    this.name=name;
    this.energy=energy;

    this.bark=()=>{
        if(energy>0){
            console.log("bark!!");
            energy--;
            this.emit('bark',this.energy);
        }
        else{
            this.emit('noEnergy');
        }
    }
}
//prototype继承EventEmitter的原型
Dog.prototype=Object.create(EventEmitter.prototype)
Dog.prototype.constructor=Dog;

module.exports= Dog
